<template>
  <div class="carousel-demo">
    <div class="demo-header">
      <h1>滑动对比轮播图演示</h1>
    </div>

    <!-- 扇形轮播对比 -->
    <div class="demo-section">
      <h2>扇形轮播对比效果</h2>
      <FanCarousel
        :items="carouselImages"
        :auto-play="true"
        :auto-play-interval="4000"
        @slideChange="handleSlideChange"
        @itemClick="handleItemClick"
      />
    </div>

    <!-- 单独的滑动对比组件 -->
    <div class="demo-section">
      <h2>单独滑动对比效果</h2>
      <div class="slider-grid">
        <div class="slider-item" v-for="(item, index) in carouselImages" :key="index">
          <BeforeAfterSlider
            :before-image="item.beforeImage"
            :after-image="item.afterImage"
            width="320px"
            height="240px"
            :show-animation="true"
            :animation-duration="2.8"
            :show-tag="true"
            tag-text="效果展示"
            :show-labels="false"
            border-radius="12px"
            @imageClick="handleSingleImageClick"
          />
        </div>
      </div>
    </div>

    <!-- 静态对比展示 -->
    <div class="demo-section">
      <h2>静态对比展示</h2>
      <div class="static-grid">
        <div class="static-item" v-for="(item, index) in carouselImages" :key="`static-${index}`">
          <div class="static-comparison">
            <div class="static-image">
              <img :src="item.beforeImage" alt="处理前" />
              <span class="static-label">处理前</span>
            </div>
            <div class="static-image">
              <img :src="item.afterImage" alt="处理后" />
              <span class="static-label">处理后</span>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import FanCarousel from '@/components/carousel/FanCarousel.vue'
import BeforeAfterSlider from '@/components/BeforeAfterSlider.vue'

export default {
  name: 'CarouselDemo',
  components: {
    FanCarousel,
    BeforeAfterSlider
  },
  data() {
    return {
      carouselImages: [
        {
          beforeImage: require('@/assets/images/carousel/1before.jpg'),
          afterImage: require('@/assets/images/carousel/1after.jpg')
        },
        {
          beforeImage: require('@/assets/images/carousel/1.1before.jpg'),
          afterImage: require('@/assets/images/carousel/1.1after.jpg')
        },
        {
          beforeImage: require('@/assets/images/carousel/1.2before.jpg'),
          afterImage: require('@/assets/images/carousel/1.2after.jpg')
        },
        {
          beforeImage: require('@/assets/images/carousel/2before.jpg'),
          afterImage: require('@/assets/images/carousel/2after.jpg')
        },
        {
          beforeImage: require('@/assets/images/carousel/2.1before.jpg'),
          afterImage: require('@/assets/images/carousel/2.1after.jpg')
        },
        {
          beforeImage: require('@/assets/images/carousel/2.3before.jpg'),
          afterImage: require('@/assets/images/carousel/2.3after.jpg')
        }
      ]
    }
  },
  methods: {
    handleSlideChange(index) {
      console.log('轮播切换到第', index + 1, '组图片')
    },
    handleItemClick(data) {
      console.log('轮播项点击:', data)
    },
    handleSingleImageClick(data) {
      console.log('单独组件点击:', data)
    }
  }
}
</script>

<style scoped>
.carousel-demo {
  padding: 20px;
  max-width: 1400px;
  margin: 0 auto;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  min-height: 100vh;
}

.demo-header {
  text-align: center;
  margin-bottom: 40px;
  color: white;
}

.demo-header h1 {
  font-size: 32px;
  margin-bottom: 10px;
  font-weight: 600;
}

.demo-header p {
  font-size: 16px;
  opacity: 0.8;
}

.demo-section {
  background: rgba(255, 255, 255, 0.95);
  border-radius: 20px;
  padding: 30px;
  margin-bottom: 30px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
  backdrop-filter: blur(10px);
}

.demo-section h2 {
  text-align: center;
  margin-bottom: 30px;
  color: #333;
  font-size: 24px;
  font-weight: 600;
}

/* 滑动对比网格 */
.slider-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(340px, 1fr));
  gap: 30px;
  padding: 20px 0;
}

.slider-item {
  text-align: center;
}


/* 静态对比网格 */
.static-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 20px;
  padding: 20px 0;
}

.static-item {
  background: white;
  border-radius: 12px;
  padding: 15px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
  transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.static-item:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
}

.static-comparison {
  display: flex;
  gap: 10px;
  margin-bottom: 10px;
}

.static-image {
  flex: 1;
  position: relative;
  border-radius: 8px;
  overflow: hidden;
}

.static-image img {
  width: 100%;
  height: 120px;
  object-fit: cover;
  display: block;
}

.static-label {
  position: absolute;
  bottom: 4px;
  left: 4px;
  background: rgba(0, 0, 0, 0.7);
  color: white;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 500;
}


/* 响应式设计 */
@media (max-width: 768px) {
  .carousel-demo {
    padding: 15px;
  }
  
  .demo-header h1 {
    font-size: 24px;
  }
  
  .demo-section {
    padding: 20px 15px;
  }
  
  .demo-section h2 {
    font-size: 20px;
  }
  
  .slider-grid {
    grid-template-columns: 1fr;
    gap: 20px;
  }
  
  .static-grid {
    grid-template-columns: 1fr;
    gap: 15px;
  }
  
  .static-comparison {
    flex-direction: column;
  }
  
  .static-image img {
    height: 100px;
  }
}

@media (max-width: 480px) {
  .demo-header h1 {
    font-size: 20px;
  }
  
  .demo-header p {
    font-size: 14px;
  }
  
  .demo-section h2 {
    font-size: 18px;
  }
}
</style>